/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package MaterialPack;

import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import Supporter.*;

/**
 *
 * @author Van persie
 */
public class PetItem extends MaterialObject {
        
    public static final int TYPE_DRAG = 0;
    public static final int TYPE_CHECK = 1;
    
    String text = null;
    Font font = null;
    
    int orgX , orgY;
    private boolean isActived = false;
        
    private int IncrSpeed;
    private int IncrTongueLen;
    private int Price;
    private int IncrEXP;
    private int IncrPoints;
    int itemType;
    Image checkImg = null;
    public PetItem(String backgPath,String Info, int  x,int y, int wid,int hei, int type )
    {
        itemType = type;
        text = Info;
        super.GetGraphicsInfo(x, y, wid, hei);
        orgX = x;
        orgY = y;
        super.LoadImage(backgPath,true,width,height);
            
        ImageSupporter imgSupporter = new ImageSupporter();
        checkImg = imgSupporter.getImage("/Checker.png");
        checkImg = imgSupporter.transparent( ImageSupporter.scaleImage(checkImg, width/2, height/2));
        
                
        font = Font.getFont(Font.FACE_SYSTEM,Font.STYLE_PLAIN   ,Font.SIZE_SMALL);
        isVisible = true;
        isActived = false;
    }

    public void SetATT(int speed,int TongLen, int EXP,int Points, int price)
    {
        setPrice(price);
        IncrEXP = EXP;        
        IncrSpeed = speed;
        IncrTongueLen = TongLen;
        IncrPoints = Points;
    }
    public boolean Press(int x, int y)
    {
        orgX = xPos;                        
        orgY = yPos;
        
        if(isContained(x, y)){
            if(itemType == TYPE_DRAG) 
            {
                setActived(true);
            }
            
            
            return true;
        }
        return false;
    }
    public void Drag(int x, int y)
    {        
        //isDraged = true;
        if(isActived() && itemType == TYPE_DRAG )
        {
            orgX = (x - width/2);
            orgY = (y - height/2);
        }
       
    }
        
    public boolean Release(int x, int y)
    {
        if(!isContained(x + (xPos - orgX), y + (yPos - orgY)))
        {            
            return false;
        }
                   
        if(itemType == TYPE_DRAG)
            setActived(false);
           // xPos = orgX;
           // yPos = orgY;
        
            //isActived = (isActived == false && itemType == TYPE_CHECK)?true:false;
        
        return true;
    }
    public void paint(Graphics g)
    {
        if(isVisible == true)
        {
            int x,y;
            if(isActived() == true)
            {
                x = orgX;
                y = orgY;
            }
            else
            {
                x = xPos;
                y = yPos;
            }
            g.drawImage(background, x, y,Graphics.TOP | Graphics.LEFT);
            if(itemType == TYPE_CHECK && isActived())
            {
                g.drawImage(checkImg, x , y +height/2, Graphics.TOP | Graphics.LEFT);
            }
            if(text != null)
            {
                g.setFont(font);
                g.drawString(text, x + width/2 , y + height  , Graphics.HCENTER | Graphics.TOP );
            }
        }        
    }

    /**
     * @return the IncrSpeed
     */
    public int getIncrSpeed() {
        return IncrSpeed;
    }

    /**
     * @param IncrSpeed the IncrSpeed to set
     */
    public void setIncrSpeed(int IncrSpeed) {
        this.IncrSpeed = IncrSpeed;
    }

    /**
     * @return the IncrTongueLen
     */
    public int getIncrTongueLen() {
        return IncrTongueLen;
    }

    /**
     * @param IncrTongueLen the IncrTongueLen to set
     */
    public void setIncrTongueLen(int IncrTongueLen) {
        this.IncrTongueLen = IncrTongueLen;
    }

    /**
     * @return the IncrEXP
     */
    public int getIncrEXP() {
        return IncrEXP;
    }

    /**
     * @param IncrEXP the IncrEXP to set
     */
    public void setIncrEXP(int IncrEXP) {
        this.IncrEXP = IncrEXP;
    }

    /**
     * @return the IncrPoints
     */
    public int getIncrPoints() {
        return IncrPoints;
    }

    /**
     * @param IncrPoints the IncrPoints to set
     */
    public void setIncrPoints(int IncrPoints) {
        this.IncrPoints = IncrPoints;
    }

    /**
     * @return the Price
     */
    public int getPrice() {
        return Price;
    }

    /**
     * @param Price the Price to set
     */
    public void setPrice(int Price) {
        this.Price = Price;
    }

    /**
     * @return the isActived
     */
    public boolean isActived() {
        return isActived;
    }

    /**
     * @param isActived the isActived to set
     */
    public void setActived(boolean isActived) {
        this.isActived = isActived;
    }
    
}
